
package com.insigma.business.qrcode.soldier.service.impl;



import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.vo.ProcessStatusEnum;
import com.insigma.business.qrcode.soldier.dao.PlacementBatchDao;
import com.insigma.business.qrcode.soldier.dto.PlacementBatchBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementBatchDO;
import com.insigma.business.qrcode.soldier.service.PlacementBatchService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("placementBatchService")
public class PlacementBatchServiceImpl implements PlacementBatchService {

    @Autowired(required = false)
    private PlacementBatchDao placementBatchDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<PlacementBatchDO> search(final PlacementBatchBSearcher placementBatchBSearcher) {
        return placementBatchDao.search(placementBatchBSearcher);
    }
   
    @Override
    public PlacementBatchDO get(final String id){
        return placementBatchDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementBatchDO placementBatchDO){
        placementBatchDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_BATCH_ID));
        return placementBatchDao.insert(placementBatchDO);
    }

    
    @Override
    public Integer update(final PlacementBatchDO placementBatchDO){
        return placementBatchDao.update(placementBatchDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementBatchDao.delete(id,modifierType,modifierId);
    }

    @Override
    public List<PlacementBatchDO> listByPlacementId(String id) {
        return  placementBatchDao.listByPlacementId(id);
    }

    @Override
    public PlacementBatchDO getByPlacementIdAndType(String id, String type) {
        if (Strings.isBlank(type)) {
            return null;
        }
        return placementBatchDao.getByPlacementIdAndType(id, type);
    }

    @Override
    public PlacementBatchDO getCurrentBatch(String placementId) {
        return  placementBatchDao.getCurrentBatch(placementId);
    }

    @Override
    public Boolean isResultPublished(String batchId) {
        PlacementBatchDO placementBatchDO = placementBatchDao.get(batchId);

        return ProcessStatusEnum.SUCCESS.name().equals(placementBatchDO.getStatus());
    }

    @Override
    public Boolean isApplyEnd(String batchId) {
        PlacementBatchDO placementBatchDO = placementBatchDao.get(batchId);

        return placementBatchDO.getApplyEndDatetime().compareTo(new Date()) > 0;
    }



}
